package com.ogawa.networklib;

import android.content.Context;
import android.text.TextUtils;
import com.ogawa.networklib.networkBean.BaseResponseBean;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public abstract class RxObserver<T extends BaseResponseBean> implements Observer<T> {

    private Context mContext;

    public RxObserver(Context context, boolean showLoading) {
        if (context != null) {
            mContext = context;
        }
    }

    @Override
    public final void onSubscribe(Disposable d) {

    }

    @Override
    public final void onNext(T value) {
        if (TextUtils.isEmpty(value.getErrCode())) {
            return;
        }
        if ("0".equals(value.getErrCode())) {
            onSuccess(value);
        } else {
            onError(value.getErrMsg());
        }
    }

    @Override
    public final void onError(Throwable e) {
        onError(e.getMessage());
    }

    @Override
    public final void onComplete() {

    }

    public abstract void onSuccess(T t);

    public abstract void onError(String errMsg);
}